using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Member_Shop_ReceiveAddress : Member, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected Literal Addrnum;
	protected GridView GridView1;
	protected TextBox TxtUserName;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected RegularExpressionValidator RegularExpressionValidator4;
	protected HiddenField editAddressID;
	protected Shop_UserControls_HowaveProvinceCity HoWaveProvinceCity1;
	protected TextBox TxtAddress;
	protected RequiredFieldValidator RequiredFieldValidator2;
	protected TextBox TxtEmail;
	protected RegularExpressionValidator RegularExpressionValidator3;
	protected TextBox TxtZipCode;
	protected RequiredFieldValidator RequiredFieldValidator3;
	protected RegularExpressionValidator RegularExpressionValidator2;
	protected TextBox TxtPhone;
	protected RegularExpressionValidator RegularHomeTel;
	protected TextBox TxtMoblephone;
	protected RegularExpressionValidator RegularExpressionValidator1;
	protected Button ButAddress;
	protected Button ButModify;
	private Shop_Address _addr;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Shop_Address m_addr
	{
		get
		{
			Shop_Address addr;
			if (this._addr == null)
			{
				this._addr = new Shop_Address(this.conn);
				addr = this._addr;
			}
			else
			{
				addr = this._addr;
			}
			return addr;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (Fetch.Get("Action") == "delete" && Fetch.GetID("aid") != 0)
		{
			int iD = Fetch.GetID("aid");
			try
			{
				if (this.m_addr.DeleteAddress(iD, base.user.UserID))
				{
					this.WriteSuccessMsg("", Language.GetMemberMsg("Common/DeleteSuccess", new string[0]), "Shop_ReceiveAddress.aspx");
				}
				else
				{
					this.WriteErrMsg("", Language.Get("Common/Fail"), "");
				}
			}
			catch
			{
			}
		}
		else
		{
			if (!base.IsPostBack)
			{
				this.BindPage();
				base.user.GetUserInfor();
				this.HoWaveProvinceCity1.SelectedProvince = base.user.UserInforRes["Province"].ToString();
				this.HoWaveProvinceCity1.SelectedCity = base.user.UserInforRes["City"].ToString();
				this.HoWaveProvinceCity1.SelectedArea = base.user.UserInforRes["CMArea"].ToString();
			}
		}
	}
	protected void BindPage()
	{
		this.GridView1.DataSource = this.m_addr.GetAddress(base.user.UserID);
		this.GridView1.DataBind();
		if (Fetch.GetID("aid") != 0 && Fetch.Get("Action") == "modify")
		{
			DataTable addressByID = this.m_addr.GetAddressByID(Fetch.GetID("aid"), base.user.UserID);
			if (addressByID.Rows.Count > 0)
			{
				this.TxtUserName.Text = addressByID.Rows[0]["UserName"].ToString();
				this.TxtAddress.Text = addressByID.Rows[0]["Address"].ToString();
				this.TxtEmail.Text = addressByID.Rows[0]["Email"].ToString();
				this.TxtZipCode.Text = addressByID.Rows[0]["ZipCode"].ToString();
				this.TxtPhone.Text = addressByID.Rows[0]["ConectPhone"].ToString();
				this.TxtMoblephone.Text = addressByID.Rows[0]["MobilePhone"].ToString();
				this.ButAddress.Visible = false;
				this.ButModify.Visible = true;
			}
			else
			{
				this.WriteErrMsg("", Language.Get("Common/NotData"), "");
			}
		}
		else
		{
			this.TxtEmail.Text = base.user.UserEmail;
		}
	}
	protected void ButAddress_Click(object sender, EventArgs e)
	{
		if (this.Page.IsValid)
		{
			int num = 10;
			try
			{
				num = int.Parse(this.Addrnum.Text);
			}
			catch
			{
			}
			string text = this.TxtAddress.Text;
			string selectedProvince = this.HoWaveProvinceCity1.SelectedProvince;
			string selectedCity = this.HoWaveProvinceCity1.SelectedCity;
			string selectedArea = this.HoWaveProvinceCity1.SelectedArea;
			if (!this.m_addr.IsMaxCount(base.user.UserID, num))
			{
				this.m_addr.InsertAddress(base.user.UserID, this.TxtUserName.Text, text, this.TxtZipCode.Text, this.TxtPhone.Text, this.TxtMoblephone.Text, this.TxtEmail.Text, selectedProvince, selectedCity, selectedArea);
				this.ButModify.Visible = false;
				this.WriteSuccessMsg("", Language.GetMemberMsg("Common/AddSuccess", new string[0]), "Shop_ReceiveAddress.aspx");
			}
			else
			{
				this.WriteErrMsg("", Language.GetMemberMsg("Address/AddNoMore", new string[0]), "");
			}
		}
	}
	protected void ButModifyAddress_Click(object sender, EventArgs e)
	{
		if (this.Page.IsValid)
		{
			string text = this.TxtAddress.Text;
			this.m_addr.UpdateAddress(base.user.UserID, base.Server.HtmlEncode(this.TxtUserName.Text), text, this.TxtZipCode.Text, this.TxtPhone.Text, base.Server.HtmlEncode(this.TxtMoblephone.Text), this.TxtEmail.Text, int.Parse(this.editAddressID.Value.ToString()), this.HoWaveProvinceCity1.SelectedProvince, this.HoWaveProvinceCity1.SelectedCity, this.HoWaveProvinceCity1.SelectedArea);
			this.ButAddress.Visible = true;
			this.ButModify.Visible = false;
			this.editAddressID.Value = "0";
			this.WriteSuccessMsg("", Language.GetMemberMsg("Common/EditSuccess", new string[0]), "Shop_ReceiveAddress.aspx");
		}
	}
	protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
	{
		HiddenField hiddenField = (HiddenField)this.GridView1.Rows[e.RowIndex].FindControl("hdAddressID");
		this.m_addr.DeleteAddress(int.Parse(hiddenField.Value), base.user.UserID);
		this.WriteSuccessMsg("", Language.GetMemberMsg("Common/DeleteSuccess", new string[0]), "Shop_ReceiveAddress.aspx");
	}
	protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
	{
		GridViewRow gridViewRow = this.GridView1.Rows[e.NewEditIndex];
		this.TxtUserName.Text = gridViewRow.Cells[0].Text.ToString();
		this.HoWaveProvinceCity1.SelectedProvince = ((Literal)gridViewRow.Cells[1].FindControl("Province")).Text.ToString();
		this.HoWaveProvinceCity1.SelectedCity = ((Literal)gridViewRow.Cells[1].FindControl("City")).Text.ToString();
		this.HoWaveProvinceCity1.SelectedArea = ((Literal)gridViewRow.Cells[1].FindControl("ltrArea")).Text.ToString();
		this.HoWaveProvinceCity1.Bind();
		this.TxtAddress.Text = gridViewRow.Cells[2].Text.ToString();
		this.TxtEmail.Text = gridViewRow.Cells[6].Text.ToString();
		Label label = (Label)gridViewRow.FindControl("lbZipCode");
		this.TxtZipCode.Text = label.Text;
		HiddenField hiddenField = (HiddenField)gridViewRow.FindControl("hdAddressID");
		this.editAddressID.Value = hiddenField.Value;
		string text = gridViewRow.Cells[3].Text.ToString();
		string text2 = gridViewRow.Cells[4].Text.ToString();
		if (text.Equals("&nbsp;"))
		{
			this.TxtPhone.Text = "";
		}
		else
		{
			this.TxtPhone.Text = text;
		}
		if (text2.Equals("&nbsp;"))
		{
			this.TxtMoblephone.Text = "";
		}
		else
		{
			this.TxtMoblephone.Text = text2;
		}
		this.ButModify.Visible = true;
		this.ButAddress.Visible = false;
	}
	protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
	{
		GridViewRow gridViewRow = this.GridView1.Rows[e.NewSelectedIndex];
		this.TxtUserName.Text = gridViewRow.Cells[0].Text.ToString();
		this.HoWaveProvinceCity1.SelectedProvince = ((Literal)gridViewRow.Cells[1].FindControl("Province")).Text.ToString();
		this.HoWaveProvinceCity1.SelectedCity = ((Literal)gridViewRow.Cells[1].FindControl("City")).Text.ToString();
		this.HoWaveProvinceCity1.SelectedArea = ((Literal)gridViewRow.Cells[1].FindControl("ltrArea")).Text.ToString();
		this.HoWaveProvinceCity1.Bind();
		this.TxtAddress.Text = gridViewRow.Cells[2].Text.ToString();
		this.TxtEmail.Text = gridViewRow.Cells[6].Text.ToString();
		Label label = (Label)gridViewRow.FindControl("lbZipCode");
		this.TxtZipCode.Text = label.Text;
		HiddenField hiddenField = (HiddenField)gridViewRow.FindControl("hdAddressID");
		this.editAddressID.Value = hiddenField.Value;
		string text = gridViewRow.Cells[3].Text.ToString();
		string text2 = gridViewRow.Cells[4].Text.ToString();
		if (text.Equals("&nbsp;"))
		{
			this.TxtPhone.Text = "";
		}
		else
		{
			this.TxtPhone.Text = text;
		}
		if (text2.Equals("&nbsp;"))
		{
			this.TxtMoblephone.Text = "";
		}
		else
		{
			this.TxtMoblephone.Text = text2;
		}
		this.ButModify.Visible = true;
		this.ButAddress.Visible = false;
	}
}
